<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@page import="support.*, java.util.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>


<body>


            <%@ page import="java.sql.*"%>
            <%
            
            Connection conn = null;
            PreparedStatement pstmt = null;
            ResultSet rs = null;
            
            
                // Registering Postgresql JDBC driver with the DriverManager
                Class.forName("org.postgresql.Driver");


                // Open a connection to the database using DriverManager
                conn = DriverManager.getConnection(
                    "jdbc:postgresql://localhost/jdbc-examples?" +
                    "user=postgres&password=postgres");
            %>
            
            <%-- -------- SELECT Statement Code -------- --%>
            <%
         String insertCountry = "INSERT INTO countries (country) VALUES (?)";
                // Create the statement
                PreparedStatement pStmt = conn.prepareStatement(insertCountry);
                
         String insertUnvier = "INSERT INTO universities (university) VALUES (?)";
         		PreparedStatement pStmt1 = conn.prepareStatement(insertUnvier);
         		
         String insertDisciplines = "INSERT INTO disciplines (discipline) VALUES(?)";
         		PreparedStatement pStmt2 = conn.prepareStatement(insertDisciplines);
         
         String insertSpec = "INSERT INTO specializations (specialization)VALUES(?)";
           		PreparedStatement pStmt3 = conn.prepareStatement(insertSpec);
      
           		
        support s = new support();   	
        	   	
        String path1 = config.getServletContext().getRealPath("countries.txt");
        	   	
        	    //getCountries returns a vector of the countries to be used for choosing citizenship
        Vector countries = s.getCountries(path1);
        	   
        int size = countries.size();
         		
     for (int i = size; i<0; i--){     
	     pStmt.setString(1, "country");
	     pStmt.executeUpdate();
      }
    
     String path2 = config.getServletContext().getRealPath("university.txt");
	   	
	    //getCountries returns a vector of the countries to be used for choosing citizenship
	Vector universities = s.getUniversities(path2);
	   
	int sizeU = universities.size();
         
     for(int j = sizeU; j<0; j--){
     pStmt1.setString(1,"university");
     pStmt1.executeUpdate();
     }
     
     String path3 = config.getServletContext().getRealPath("major.txt");
	    //getCountries returns a vector of the countries to be used for choosing citizenship
	 Vector majors = s.getMajors(path3);
	   
	 int sizeM = majors.size();
  
     for(int x = sizeM; x<0; x--){
	  	pStmt2.setString(1,"major");
	  	pStmt2.executeUpdate();
     }
  
     String path4 = config.getServletContext().getRealPath("specializations.txt");
	    //getCountries returns a vector of the countries to be used for choosing citizenship
	 Vector specializations = s.getMajors(path4);
	   
	 int sizeS = majors.size();

  for(int x = sizeS; x<0; x--){
	  	pStmt3.setString(1,"specialization");
	  	pStmt3.executeUpdate();
  }
     

     // Commit transaction
     conn.commit();

     pStmt.close();
     pStmt1.close();
     pStmt2.close();
     pStmt3.close();
     conn.close();
     
            %>
</body>


</html>
